package com.hopu.v1.controller.admin.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.system.StaffRole;
import com.hopu.v1.service.admin.system.StaffRoleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (StaffRole)表控制层
 *
 * @author makejava
 * @since 2024-09-13 19:30:43
 */
@RestController
@RequestMapping("staffRole")
public class StaffRoleController {
    /**
     * 服务对象
     */
    @Resource
    private StaffRoleService staffRoleService;

    /**
     * 分页查询所有数据
     *
     * @param page      分页对象
     * @param staffRole 查询实体
     * @return 所有数据
     */
    @GetMapping("/selectAll")
    public R selectAll(Page<StaffRole> page, StaffRole staffRole) {
        return R.ok(this.staffRoleService.page(page, new QueryWrapper<>(staffRole)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param roleId 角色主键
     * @return 单条数据
     */
    @GetMapping("/selectOne/{roleId}")
    public R selectOne(@PathVariable Integer roleId) {
        return R.ok(this.staffRoleService.getById(roleId));
    }


    /**
     * 修改数据
     *
     * @param staffRole 实体对象
     * @return 修改结果
     */
    @PutMapping("/update")
    public R update(@RequestBody StaffRole staffRole) {
        return R.ok(this.staffRoleService.updateById(staffRole));
    }





    /**
     * 修改角色信息
     * @param roleId
     * @param roleNameList
     * @return
     */
    @PutMapping("updateStaffRole")
    public R updateRoleName(@RequestParam(value = "roleId") Integer roleId, @RequestParam(value = "roleNameList",required = false) List<Integer> roleNameList) {
        System.out.println(roleId);
        System.out.println(roleNameList);
        this.staffRoleService.updateRoleName(roleId,roleNameList);
        return R.ok("修改成功");
    }

    @GetMapping("getRoleById/{roleId}")
    public R getRoleById(@PathVariable Integer roleId) {
        return R.ok(this.staffRoleService.getRoleById(roleId));
    }

}
